﻿using System;
using Token.Piker.BLL;
using Token.Piker.Model;

namespace Token.Piker.Web.Admin.NewsAlbum
{
    public partial class PhotoDetails : System.Web.UI.Page
    {
        NewsPhotoBLL bll = new NewsPhotoBLL();
        static NewsPhoto photo;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.Params["ID"]))
            {
                int id = int.Parse(Request.Params["ID"]);
                ShowInfo(id);
            }
        }

        private void ShowInfo(int id)
        {
            photo = bll.GetModel(id);
            lblPhotoName.Text = photo.PhotoName;
            lblDescrip.Text = photo.Descrip;
            lblUploadTime.Text = ((DateTime)photo.UploadTime).ToString();
            anchorSource.HRef = photo.SourceUrl;
            anchorcmpress1.HRef = photo.CompressUrl_1;
            anchorcmpress2.HRef = photo.CompressUrl_2;
            anchorcmpress3.HRef = photo.CompressUrl_2;
            anchorcmpress4.HRef = photo.CompressUrl_2;
            NewsAlbumBLL albumBLL = new NewsAlbumBLL();
            Token.Piker.Model.NewsAlbum album = albumBLL.GetModel((int)photo.Album);
            lblAlbum.Text = album.AlbumName;
            lkbFlag.Text = photo.Flag.ToString() == "0" ? "正常" : "已删除";
        }

        protected void lkbFlag_Click(object sender, EventArgs e)
        {
            //更改图片状态
            if (lkbFlag.Text == "正常")
            {
                photo.Flag = 1;
            }
            else
            {
                photo.Flag = 0;
            }

            if (bll.Update(photo) == true)
            {
                lkbFlag.Text = photo.Flag == 0 ? "正常" : "已删除";
            }
        }
    }
}